jQuery(function ($) {
    var user = JSON.parse(localStorage.getItem('user_info')) || {};
    var id = user.id;
    if (id) {
        $('.nologin-tip').hide();
    } else {
        $('.nologin-tip').show();
    }
    var arr_goods_id = []; //全选提交选中的状态
    var goods_id_All = []; //全选提交取消选中的状态
    var off = true;
    // var timer;
    new Vue({
        el: '#container',
        data: function data() {
            return {
                dest: [], //请求的购物车列表数据
                isCheckedAll: false, //是否全选
                rules: [], //渲染活动的列表
                activity_rule_id: -1, //用在选择活动,传参用的
                cart_id: -1, //当前选择的购物车id，用在选择活动
                number: 0, //选中的商品数量
                currentGoodsIndex: -1, //切换活动列表块显示隐藏
                currentActivityIndex: -1,
                order_start: -1, //商品结算规则
                discount_start: -1,
                order_step: -1,
                discount_step: -1,
                discount_max: -1,
                giveGift: [], //赠品列表
                giftBtnOff: false, //赠品按钮显示隐藏
                markUpBtnOff: false, //加价购按钮显示隐藏
                couponOff: false,
                giftId: -3,
                coupon: '优惠券',
                giveGiftOff: false, //赠品块切换显示
                giveGiftCheckedOff: false, //赠品选择点击按钮切换颜色
                purchasedOff: false, //加价购列表切换显示
                markUplIist: [], //加价购商品列表
                markUplIistChoose: [], //加价购选择的商品id
                giveGiftChoose: [], //赠品选择的数组商品id
                totalPrice: { totalSum: 0, discountAmt: 0 }, //获取的总价格\
                noUserGoodsList: [], //没有用户登录的商品列表
                noLoginPrice: 0, //计算价格
                noLoginPriceString: 0, //显示计算的价格
                storeNoLoginGoodsId: [], //储存无登录选中的商品用来记录全选，删除用
                isUser: id ? true : false
            };
        },
        methods: {
            sales_drop: function sales_drop(activityIndex, goodsIndex, goods_id) {
                if (this.currentGoodsIndex == goodsIndex && this.currentActivityIndex == activityIndex) {
                    this.currentGoodsIndex = -1;
                    this.currentActivityIndex = -1;
                    return;
                }
                var _this = this;
                var user = JSON.parse(localStorage.getItem('user_info')) || {};
                var level_id = user.level_id;
                var params = {
                    "level_id": level_id,
                    "goods_id": goods_id
                };
                send_ajax('post', '/api/activity/available', params, function (data) {
                    if (data.code == 200) {
                        _this.rules = data.data;
                        _this.currentActivityIndex = activityIndex;
                        _this.currentGoodsIndex = goodsIndex;
                    }
                });
            },
            //单选
            singleChecked: function singleChecked(item, option) {
                // goods_price=[];
                var _this = this;
                var arr = [];
                arr.push(item.Goods.id);
                item.Cart.selected_flag = !item.Cart.selected_flag;
                var param;
                if (item.Cart.selected_flag == true) {
                    param = {
                        user_id: id,
                        goods_ids: arr,
                        select_flag: 1
                    };
                } else {
                    param = {
                        user_id: id,
                        goods_ids: arr,
                        select_flag: 0
                    };
                }
                send_ajax('post', '/api/cart/select', param, function callback(data) {
                    if (data.code == 200) {
                        _this.getTotalPrice();
                    }
                });
                for (var i = 0; i < arr_goods_id.length; i++) {
                    if (item.Cart.selected_flag == false && arr_goods_id[i] == item.Goods.id) {
                        arr_goods_id.splice(i, 1);
                    }
                };
                this.couponRecord(item, option);
                this.isSelected(item, option);
                this.count_price();
            },
            //是否全选
            isSelectedAll: function isSelectedAll() {
                var flag = true;
                for (var i = 0; i < this.dest.length; i++) {
                    for (var n = 0; n < this.dest[i].data.length; n++) {
                        if (!this.dest[i].data[n].Cart.selected_flag) {
                            flag = false;
                        }
                    }
                }
                this.isCheckedAll = flag ? true : false;
            },
            //是否有选中的商品
            isSelected: function isSelected(item, option) {
                var _this = this;
                //判断id相同价格就相加起来且不是特价商品
                if (item.Activity && item.Goods.promotion_flag != 1) {
                    //那到所有的有活动的商品,ActivityDerate只是满减/满折/满送;
                    //1.正常商品
                    if (item.Goods.gift_flag == false) {
                        if (item.Cart.selected_flag == true && item.Cart.activity_id == option.id) {
                            //选中，加上价格
                            option.marketPrice += item.Goods.promotion_price;
                            option.fullPrice++;
                        } else {
                            //取消选中
                            //有没有赠品加价购商品
                            var ActivityGiftGoods = option.data.filter(function (el) {
                                return el.ActivityGiftGoods;
                            });
                            if (ActivityGiftGoods.length !== 0) {
                                var arr = [];
                                arr.push(item.Goods.id);
                                var param = {
                                    user_id: id,
                                    goods_ids: arr,
                                    select_flag: 1
                                };
                                //满件
                                if (item.ActivityGift.full_type == 2 && option.fullPrice - 1 < item.ActivityGift.order_full) {
                                    swal({
                                        text: "取消此商品后将不满足赠品/加价购/购买条件，是否删除!",
                                        type: 'warning',
                                        showCancelButton: true,
                                        confirmButtonColor: '#3AD997',
                                        cancelButtonColor: '#EEE',
                                        confirmButtonText: '确定',
                                        cancelButtonText: '取消'
                                    }).then(function (isConfirm) {
                                        if (isConfirm) {
                                            var gifeGoodsAll = _this.giveGiftChoose.concat(_this.markUplIistChoose);
                                            var giftAll = {
                                                user_id: id,
                                                goods_ids: gifeGoodsAll,
                                                type: 0
                                            };
                                            send_ajax('post', '/api/cart/add', giftAll, function callback(data) {
                                                if (data.code == 200) {
                                                    option.marketPrice -= item.Goods.goods_price;
                                                    option.fullPrice--;
                                                    for (var i = 0; i < gifeGoodsAll.length; i++) {
                                                        _this.deletesGoods(option, gifeGoodsAll[i]);
                                                    }
                                                }
                                            });
                                        } else {
                                            send_ajax('post', '/api/cart/select', param, function callback(data) {
                                                if (data.code == 200) {
                                                    _this.again_data();
                                                }
                                            });
                                        }
                                    });
                                } else if (item.ActivityGift.full_type == 1 && option.marketPrice - item.Goods.promotion_price < item.ActivityGift.order_full) {
                                    //满额
                                    swal({
                                        // title: 'Are you sure?',
                                        text: "删除此商品后将不满足赠品/加价购/购买条件，是否删除!",
                                        type: 'warning',
                                        showCancelButton: true,
                                        confirmButtonColor: '#3AD997',
                                        cancelButtonColor: '#EEE',
                                        confirmButtonText: '确定',
                                        cancelButtonText: '取消'
                                    }).then(function (isConfirm) {
                                        if (isConfirm) {
                                            var gifeGoodsAll = _this.giveGiftChoose.concat(_this.markUplIistChoose);
                                            var giftAll = {
                                                user_id: id,
                                                goods_ids: gifeGoodsAll,
                                                type: 0
                                                //删除全部赠品/加价购
                                            };
                                            send_ajax('post', '/api/cart/add', giftAll, function callback(data) {
                                                if (data.code == 200) {
                                                    option.marketPrice -= item.Goods.goods_price;
                                                    option.fullPrice--;
                                                    for (var i = 0; i < gifeGoodsAll.length; i++) {
                                                        _this.deletesGoods(option, gifeGoodsAll[i]);
                                                    }
                                                }
                                            });
                                        } else {
                                            send_ajax('post', '/api/cart/select', param, function callback(data) {
                                                if (data.code == 200) {
                                                    _this.again_data();
                                                }
                                            });
                                        }
                                    });
                                } else {
                                    option.marketPrice -= item.Goods.promotion_price;
                                    option.fullPrice--;
                                }
                            } else {
                                // option.marketPrice-=item.Goods.goods_price;
                                // option.fullPrice--;

                                //查询优惠券
                                if (item.Coupon) {
                                    var couponParams = {
                                        'CartCoupon': {
                                            'user_id': id,
                                            'activity_id': item.Activity.id
                                        }
                                    };
                                    send_ajax('post', '/get', couponParams, function callback(data) {
                                        if (data.code == 200 && data.CartCoupon) {
                                            //优惠券记录删除
                                            if (item.Coupon && item.ActivityVirtual.full_type == 2 && option.fullPrice - 1 < item.ActivityVirtualCoupon.order_full) {
                                                swal({
                                                    text: "取消此商品后将不满足优惠券领取，是否取消!",
                                                    type: 'warning',
                                                    showCancelButton: true,
                                                    confirmButtonColor: '#3AD997',
                                                    cancelButtonColor: '#EEE',
                                                    confirmButtonText: '确定',
                                                    cancelButtonText: '取消'
                                                }).then(function (isConfirm) {
                                                    if (isConfirm) {
                                                        var param_d = {
                                                            'CartCoupon': {
                                                                'user_id': id,
                                                                'coupon_id': item.Coupon.id,
                                                                'activity_id': item.Activity.id
                                                            },
                                                            'Tag': 'CartCoupon'
                                                        };
                                                        send_ajax('post', '/delete', param_d, function callback(data) {
                                                            if (data.code == 200) {
                                                                option.marketPrice -= item.Goods.goods_price;
                                                                option.fullPrice--;
                                                                _this.again_data();
                                                            }
                                                        });
                                                    } else {
                                                        var arr = [];
                                                        arr.push(item.Goods.id);
                                                        var param = {
                                                            user_id: id,
                                                            goods_ids: arr,
                                                            select_flag: 1
                                                        };
                                                        send_ajax('post', '/api/cart/select', param, function callback(data) {
                                                            if (data.code == 200) {
                                                                _this.again_data();
                                                            }
                                                        });
                                                    }
                                                });
                                                var param = {
                                                    'CartCoupon': {
                                                        'user_id': id,
                                                        'coupon_id': item.Coupon.id,
                                                        'activity_id': item.Activity.id
                                                    },
                                                    'Tag': 'CartCoupon'
                                                };
                                                send_ajax('post', '/delete', param, function callback(data) {
                                                    if (data.code == 200) {
                                                        alert('删除成功');
                                                    } else {
                                                        alert('data.msg');
                                                    }
                                                });
                                            } else if (item.Coupon && item.ActivityVirtual.full_type == 1 && option.marketPrice - item.Goods.promotion_price < item.ActivityVirtualCoupon.order_full) {
                                                swal({
                                                    // title: 'Are you sure?',
                                                    text: "取消此商品后将不满足优惠券领取，是否取消!",
                                                    type: 'warning',
                                                    showCancelButton: true,
                                                    confirmButtonColor: '#3AD997',
                                                    cancelButtonColor: '#EEE',
                                                    confirmButtonText: '确定',
                                                    cancelButtonText: '取消'
                                                }).then(function (isConfirm) {
                                                    if (isConfirm) {
                                                        var delete_param = {
                                                            'CartCoupon': {
                                                                'user_id': id,
                                                                'coupon_id': item.Coupon.id,
                                                                'activity_id': item.Activity.id
                                                            },
                                                            'Tag': 'CartCoupon'
                                                        };
                                                        send_ajax('post', '/delete', delete_param, function callback(data) {
                                                            if (data.code == 200) {

                                                                option.marketPrice -= item.Goods.goods_price;
                                                                option.fullPrice--;
                                                                _this.again_data();
                                                            }
                                                        });
                                                    } else {
                                                        var arr = [];
                                                        arr.push(item.Goods.id);
                                                        var param = {
                                                            user_id: id,
                                                            goods_ids: arr,
                                                            select_flag: 1
                                                        };
                                                        send_ajax('post', '/api/cart/select', param, function callback(data) {
                                                            if (data.code == 200) {
                                                                _this.again_data();
                                                            }
                                                        });
                                                    }
                                                });
                                            } else {
                                                option.marketPrice -= item.Goods.promotion_price;
                                                option.fullPrice--;
                                            }
                                        } else {
                                            option.marketPrice -= item.Goods.promotion_price;
                                            option.fullPrice--;
                                        }
                                    });
                                } else {
                                    option.marketPrice -= item.Goods.promotion_price;
                                    option.fullPrice--;
                                }
                            }
                        }
                    } else {
                        //2.加价购或者是赠品
                        if (item.Cart.selected_flag == true && item.Cart.activity_id == option.id) {
                            if (item.Goods.gift_flag && item.ActivityGiftGoods && item.ActivityGiftGoods.add_price == 0) {
                                if (this.giveGiftChoose.indexOf(item.Goods.id) == -1) {
                                    this.giveGiftChoose.push(item.Goods.id);
                                }
                            } else if (item.Goods.gift_flag && item.ActivityGiftGoods && item.ActivityGiftGoods.add_price > 0) {
                                if (this.markUplIistChoose.indexOf(item.Goods.id) == -1) {
                                    this.markUplIistChoose.push(item.Goods.id);
                                }
                            }
                            option.marketPrice += item.ActivityGiftGoods.add_price;
                            // option.fullPrice++;
                        } else {
                            option.marketPrice -= item.ActivityGiftGoods.add_price;
                            // option.fullPrice--;
                        }
                    }
                } else {
                    if (item.Cart.selected_flag == true && item.Goods.promotion_flag != 1) {
                        option.marketPrice += item.Goods.promotion_price;
                    } else if (item.Cart.selected_flag == true && item.Goods.promotion_flag == 1) {
                        option.marketPrice += item.Goods.promotion_price;
                        option.bargains += item.Goods.promotion_price;
                    } else {
                        if (item.Cart.selected_flag == false && item.Goods.promotion_flag != 1) {
                            option.marketPrice -= item.Goods.promotion_price;
                        } else if (item.Cart.selected_flag == false && item.Goods.promotion_flag == 1) {
                            option.marketPrice -= item.Goods.promotion_price;
                            option.bargains -= item.Goods.promotion_price;
                        }
                    }
                }
                //判断一共选中了几件商品
                if (item.Cart.selected_flag == true) {
                    if (arr_goods_id.indexOf(item.Goods.id) == -1) {
                        arr_goods_id.push(item.Goods.id);
                    }
                    this.number++;
                } else {
                    this.number--;
                }
                this.isSelectedAll();
                this.currentGoodsIndex = -1;
                this.currentActivityIndex = -1;
                this.rules = [];
            },

            // 优惠券记录
            couponRecord: function couponRecord(item, option) {
                if (item.Activity && item.Goods.promotion_flag != 1) {
                    //那到所有的有活动的商品,ActivityDerate只是满减/满折/满送
                    //1.正常商品
                    if (item.Goods.gift_flag == false) {
                        if (item.Cart.selected_flag == true && item.Cart.activity_id == option.id) {
                            //选中，加上价格
                            //优惠券记录

                            if (item.Coupon && option.fullPrice < item.ActivityVirtualCoupon.order_full && option.fullPrice + 1 >= item.ActivityVirtualCoupon.order_full && item.ActivityVirtual.full_type == 2) {
                                var param = {
                                    'CartCoupon': {
                                        'user_id': id,
                                        'coupon_id': item.Coupon.id,
                                        'activity_id': item.Activity.id
                                    },
                                    'Tag': 'CartCoupon'
                                };
                                send_ajax('post', '/post', param, function callback(data) {
                                    if (data.code == 200) {}
                                });
                            } else if (item.Coupon && option.marketPrice < item.ActivityVirtualCoupon.order_full && option.marketPrice + item.Goods.goods_price >= item.ActivityVirtualCoupon.order_full && item.ActivityVirtual.full_type == 1) {
                                var param = {
                                    'CartCoupon': {
                                        'user_id': id,
                                        'coupon_id': item.Coupon.id,
                                        'activity_id': item.Activity.id
                                    },
                                    'Tag': 'CartCoupon'
                                };
                                send_ajax('post', '/post', param, function callback(data) {
                                    if (data.code == 200) {}
                                });
                            }
                        }
                    }
                }
            },

            //数据从新分类渲染
            again_data: function again_data() {
                //是不是有不登录存的商品
                var isStoreGoods = JSON.parse(localStorage.getItem('noUsers')) || {};
                this.number = 0;
                this.dest = [];
                var _this = this;
                //购物车参数
                var param = {
                    '[]': {
                        'Cart': {
                            'user_id': id
                        },
                        "count": 0,
                        'Goods': {
                            'id@': '/Cart/goods_id'
                        },
                        'GoodsImgs': {
                            'main_flag': 1,
                            'goods_id@': '/Cart/goods_id'
                        },
                        'Activity': {
                            'id@': '/Cart/activity_id'
                        },
                        'ActivityDerate': {
                            'activity_id@': '/Activity/id'
                        },
                        'ActivityGift': {
                            'activity_id@': '/Activity/id'
                        },
                        'ActivityGiftGoods': {
                            'activity_gift_id@': '/ActivityGift/id',
                            'goods_id@': '/Cart/goods_id'
                        },
                        'ActivityVirtual': {
                            'activity_id@': '/Activity/id'
                        },
                        'ActivityVirtualCoupon': {
                            'virtual_id@': '/ActivityVirtual/id'
                        },
                        'Coupon': {
                            'id@': '/ActivityVirtualCoupon/coupon_id'
                        }
                    }
                };
                if (id) {
                    var tempDate = [];
                    var map = {};
                    var obj = {};
                    send_ajax('post', '/get', param, function callback(result) {
                        console.log(result)
                        if (result.code == 200 && result["[]"]) {
                            var data = result["[]"];
                            // var goodsIdArr=[];
                            // for (var i = 0; i < data.length; i++) {
                            //     if(data[i].Goods){
                            //          goodsIdArr.push(data[i].Goods.id)
                            //     }
                               
                            // };
                            // var params={
                            //     'user_id': id ? id : 0,
                            //     'goodsIdList': goodsIdArr.join(',')
                            // }
                            // send_ajax('get', '/api/goods/status', params, function callback(res) {
                                // if(res.code==200&&res.data){
                                    // var result = res.data;
                                    console.log(data)
                                    for(var i = 0;i<data.length;i++){
                                        if(data[i].Goods){
                                            data[i].Goods.goodsPrice = keepTwoDecimalFull(data[i].Goods.goods_price);
                                            data[i].GoodsImgs.thumb = isImgHttp(data[i].GoodsImgs.thumb);
                                            var goodsId = data[i].Goods.id;
                                            if(result[goodsId] != undefined){
                                                data[i].Goods.promotion_flag = result[goodsId].goodsStatus;
                                                data[i].Goods.promotion_price = result[goodsId].price;
                                                data[i].Goods.promotionPrice = keepTwoDecimalFull(data[i].Goods.promotion_price);

                                            }
                                        }
                                      
                                        var item = data[i];
                                        if (item.Goods) {
                                            if (!item.Cart.activity_id) {
                                                item.Cart.activity_id = 0;
                                            }
                                            var ai = item;
                                            if (ai.ActivityDerate) {
                                                item.ActivityDerate.derate = JSON.parse(item.ActivityDerate.derate);
                                            };
                                            if (!map[ai.Cart.activity_id] && (ai.Goods.gift_flag || ai.Goods.promotion_flag != 1)) {
                                                tempDate.push({
                                                    id: ai.Cart.activity_id ? ai.Cart.activity_id : 0,
                                                    onOff: false,
                                                    marketPrice: 0, //计算的总价格
                                                    total_price: 0, //用来显示计算的价格（解决计算的时候number类型）
                                                    couponOff: true,
                                                    subtotal: 0,
                                                    reducePrice: 0,
                                                    fullPrice: 0,
                                                    title: 0,
                                                    data: [ai]
                                                });
                                                map[ai.Cart.activity_id] = ai;
                                            } else {
                                                for (var j = 0; j < tempDate.length; j++) {
                                                    var dj = tempDate[j];
                                                    if (dj.id == ai.Cart.activity_id && (ai.Goods.gift_flag || ai.Goods.promotion_flag != 1)) {
                                                        dj.data.push(ai);
                                                        break;
                                                    }
                                                };
                                            };
                                            if (!obj[ai.Goods.promotion_flag] && ai.Goods.promotion_flag == 1) {
                                                tempDate.push({
                                                    promotion_flag: ai.Goods.promotion_flag,
                                                    id: -5,
                                                    onOff: false,
                                                    marketPrice: 0,
                                                    total_price: 0,
                                                    subtotal: 0,
                                                    couponOff: true,
                                                    reducePrice: 0,
                                                    fullPrice: 0,
                                                    title: 0,
                                                    bargains: 0,
                                                    data: [ai]
                                                });
                                                obj[ai.Goods.promotion_flag] = ai;
                                            } else {
                                                for (var j = 0; j < tempDate.length; j++) {
                                                    var dj = tempDate[j];
                                                    if (dj.promotion_flag == ai.Goods.promotion_flag) {
                                                        dj.data.push(ai);
                                                        break;
                                                    }
                                                };
                                            };
    
                                            // for (var k = 0; k < _this.dest.length; k++) {
                                            //     for (var n = 0; n < _this.dest[k].data.length; n++) {
                                            //         goods_id_All.push(_this.dest[k].data[n].Goods.id);
                                            //         if (_this.dest[k].data[n].Cart.selected_flag == true) {
                                            //             _this.isSelected(_this.dest[k].data[n], _this.dest[k]);
                                            //         }
                                            //     }
                                            // };
                                        };
                                    }
                                    var g = new util();
                                    tempDate = g.max2min(tempDate);
                                    _this.dest = [].concat(tempDate);
                                    for (var k = 0; k < _this.dest.length; k++) {
                                        for (var n = 0; n < _this.dest[k].data.length; n++) {
                                            goods_id_All.push(_this.dest[k].data[n].Goods.id);
                                            if (_this.dest[k].data[n].Cart.selected_flag == true) {
                                                _this.isSelected(_this.dest[k].data[n], _this.dest[k]);
                                            }
                                        }
                                    };
                                    _this.getTotalPrice();
                                    _this.count_price();
                                // }
                               
                            // });
                         
                        } else {
                            _this.isCheckedAll = false;
                        }
                    });
                } else {
                    var goodsList = JSON.parse(localStorage.getItem('noUsers')) || [];
                    if (goodsList.length) {
                        _this.noUserGoodsList = goodsList;
                        _this.noUserPrice();
                    } else {}
                }
            },

            //全选
            checkAll: function checkAll() {
                var _this = this;
                arr_goods_id = [];
                // goods_id_All=[];
                this.number = 0;
                var goods_price = [];
                this.isCheckedAll = !this.isCheckedAll;
                var checkedAll = this.isCheckedAll;
                for (var i = 0; i < this.dest.length; i++) {
                    this.dest[i].marketPrice = 0;
                    this.dest[i].fullPrice = 0;
                    this.dest[i].bargains = 0;
                    for (var n = 0; n < this.dest[i].data.length; n++) {
                        //全选状态的改变
                        if (this.dest[i].data[n].Goods.gift_flag == false) {
                            this.dest[i].data[n].Cart.selected_flag = checkedAll;
                        }
                        //如果是全是true
                        if (this.dest[i].data[n].Cart.selected_flag) {
                            this.couponRecord(this.dest[i].data[n], this.dest[i]);
                            this.isSelected(this.dest[i].data[n], this.dest[i]);
                        } else {
                            if (goods_id_All.indexOf(this.dest[i].data[n].Goods.id) == -1) {
                                goods_id_All.push(this.dest[i].data[n].Goods.id);
                            };
                            arr_goods_id = [];
                            this.number = 0;
                            this.dest[i].bargains = 0;
                            this.dest[i].fullPrice = 0;
                            this.dest[i].marketPrice = 0;
                            this.dest[i].reducePrice = 0;
                            this.dest[i].subtotal = 0;
                        }
                    }
                }
                var param;
                if (checkedAll) {
                    param = {
                        user_id: id,
                        goods_ids: arr_goods_id,
                        select_flag: 1
                    };
                } else {
                    param = {
                        user_id: id,
                        goods_ids: goods_id_All,
                        select_flag: 0
                    };

                    if (this.giveGiftChoose.concat(this.markUplIistChoose).length != 0) {
                        var giftAll = {
                            user_id: id,
                            goods_ids: this.giveGiftChoose.concat(this.markUplIistChoose),
                            type: 0
                        };
                        send_ajax('post', '/api/cart/add', giftAll, function callback(data) {
                            if (data.code == 200) {
                                _this.again_data();
                            }
                        });
                    }
                }
                this.count_price();
                send_ajax('post', '/api/cart/select', param, function callback(data) {
                    if (data.code == 200) {
                        goods_id_All = [];
                        _this.getTotalPrice();
                    }
                });
            },
            //赠品/加价购,删除提醒
            //计算选中活动的价钱
            count_price: function count_price() {
                var _this = this;
                for (var i = 0; i < this.dest.length; i++) {
                    if (this.dest[i].data[0].ActivityDerate && !this.dest[i].data[0].ActivityGift && !this.dest[i].data[0].ActivityVirtualCoupon && this.dest[i].data[0].Goods.promotion_flag != 1) {
                        var derate = this.dest[i].data[0].ActivityDerate.derate;
                        var discount = this.dest[i].data[0].ActivityDerate.discount_type;
                        var full_type = this.dest[i].data[0].ActivityDerate.full_type;
                        var step_flag = this.dest[i].data[0].ActivityDerate.step_flag;
                        //满额减钱等步长
                        if (discount == 1 && full_type == 1 && step_flag == true) {
                            this.dest[i].title = '活动商品,购买满' + derate.order_start + '元;' + "即可享受优惠;" + '最高可享受' + derate.discount_max + '元优惠';
                            this.order_start = derate.order_start;
                            this.discount_start = derate.discount_start;
                            this.order_step = derate.order_step;
                            this.discount_step = derate.discount_step;
                            this.discount_max = derate.discount_max;
                            if (this.dest[i].marketPrice <= this.order_start) {
                                this.dest[i].onOff = false;
                                this.dest[i].total_price = keepTwoDecimalFull(this.dest[i].marketPrice);
                                this.dest[i].reducePrice = keepTwoDecimalFull(0);
                                this.dest[i].subtotal = keepTwoDecimalFull(parseFloat(this.dest[i].marketPrice));
                            } else if (this.dest[i].marketPrice == this.order_start) {
                                this.dest[i].onOff = true;
                                this.dest[i].total_price = keepTwoDecimalFull(this.dest[i].marketPrice);
                                this.dest[i].reducePrice = keepTwoDecimalFull(parseFloat(this.discount_start));
                                this.dest[i].subtotal = keepTwoDecimalFull(parseFloat(this.dest[i].reducePrice));
                                this.dest[i].title = '活动商品,已满' + derate.order_start + '元;' + '已享受' + this.dest[i].reducePrice + '优惠';
                            } else if (this.dest[i].marketPrice >= this.order_start) {
                                this.dest[i].onOff = true;
                                this.dest[i].total_price = keepTwoDecimalFull(this.dest[i].marketPrice);
                                this.dest[i].reducePrice = keepTwoDecimalFull(parseFloat((this.dest[i].marketPrice - this.order_start) / this.order_step) * this.discount_step + this.discount_start);
                                this.dest[i].subtotal = keepTwoDecimalFull(parseFloat(this.dest[i].marketPrice - this.dest[i].reducePrice));
                                this.dest[i].title = '活动商品,已满' + (parseInt((this.dest[i].marketPrice - derate.order_start) / this.order_step) * this.order_step + derate.order_start) + '元;' + '已享受' + (this.dest[i].reducePrice >= this.discount_max ? this.discount_max : this.dest[i].reducePrice) + '优惠';
                                if (this.dest[i].reducePrice >= this.discount_max) {
                                    this.dest[i].onOff = true;
                                    this.dest[i].total_price = keepTwoDecimalFull(this.dest[i].marketPrice);
                                    this.dest[i].reducePrice = keepTwoDecimalFull(parseFloat(this.discount_max));
                                    this.dest[i].subtotal = keepTwoDecimalFull(parseFloat(this.dest[i].marketPrice - this.dest[i].reducePrice));
                                }
                            }
                        } else if (discount == 1 && full_type == 2 && step_flag == true) {
                            this.dest[i].title = '活动商品,购买满' + derate.order_start + '件;' + '即享受优惠';
                            //满件减钱等步长的
                            // discount_max: 500
                            // discount_start: 10
                            // discount_step: 10
                            // order_start: 10
                            // order_step: 5
                            this.order_start = derate.order_start;
                            this.discount_start = derate.discount_start;
                            this.order_step = derate.order_step;
                            this.discount_step = derate.discount_step;
                            this.discount_max = derate.discount_max;

                            //件数小于10件不优惠
                            if (this.dest[i].fullPrice < this.order_start) {
                                this.dest[i].onOff = false;
                                this.dest[i].total_price = keepTwoDecimalFull(this.dest[i].marketPrice);
                                this.dest[i].reducePrice = keepTwoDecimalFull(0);
                                this.dest[i].subtotal = keepTwoDecimalFull(parseFloat(this.dest[i].marketPrice));
                                //件数等于10件优惠10块
                            } else if (this.dest[i].fullPrice == this.order_start) {
                                this.dest[i].onOff = true;
                                this.dest[i].total_price = keepTwoDecimalFull(this.dest[i].marketPrice);
                                this.dest[i].title = '活动商品,已满' + derate.order_start + '件;' + '已享受优惠';
                                this.dest[i].reducePrice = keepTwoDecimalFull(parseFloat(this.discount_start));
                                this.dest[i].subtotal = keepTwoDecimalFull(parseFloat(this.dest[i].marketPrice - this.discount_start));
                                //件数大于10件优惠
                            } else if (this.dest[i].fullPrice >= this.order_start) {
                                this.dest[i].onOff = true;
                                this.dest[i].total_price = keepTwoDecimalFull(this.dest[i].marketPrice);
                                this.dest[i].title = '活动商品,已满' + derate.order_start + '件;' + '已享受优惠';
                                this.dest[i].reducePrice = keepTwoDecimalFull(parseFloat((this.dest[i].fullPrice - this.order_start) / this.order_step * this.discount_step + this.discount_start));
                                this.dest[i].subtotal = keepTwoDecimalFull(parseFloat(this.dest[i].marketPrice - this.dest[i].reducePrice));

                                if (this.dest[i].reducePrice >= this.discount_max) {
                                    this.dest[i].onOff = true;
                                    this.dest[i].total_price = keepTwoDecimalFull(this.dest[i].marketPrice);
                                    this.dest[i].reducePrice = keepTwoDecimalFull(parseFloat(this.discount_max));
                                    this.dest[i].subtotal = keepTwoDecimalFull(parseFloat(this.dest[i].marketPrice - this.dest[i].reducePrice));
                                }
                            }
                        } else if (discount == 1 && full_type == 1 && step_flag == false) {
                            this.dest[i].title = '活动商品,购买满' + derate[0].order_full + '元; ' + '即减' + derate[0].discount + '元';
                            this.dest[i].onOff = false;
                            //满额减钱非等步长的
                            var maxPrice;
                            for (var k = 0; k < derate.length; k++) {
                                if (this.dest[i].marketPrice > derate[k].order_full) {
                                    maxPrice = derate[k];
                                }
                            }

                            if (maxPrice) {
                                this.dest[i].onOff = true;
                                this.dest[i].total_price = keepTwoDecimalFull(this.dest[i].marketPrice);
                                this.dest[i].title = '活动商品,已满' + maxPrice.order_full + '元; ' + '已优惠' + maxPrice.discount + '元';
                                this.dest[i].reducePrice = keepTwoDecimalFull(parseFloat(maxPrice.discount));
                                this.dest[i].subtotal = keepTwoDecimalFull(parseFloat(this.dest[i].marketPrice - this.dest[i].reducePrice));
                            } else {
                                this.dest[i].onOff = false;
                                this.dest[i].total_price = keepTwoDecimalFull(this.dest[i].marketPrice);
                                this.dest[i].reducePrice = 0;
                                this.dest[i].subtotal = keepTwoDecimalFull(parseFloat(this.dest[i].marketPrice));
                            }
                        } else if (discount == 2 && full_type == 1 && step_flag == false) {
                            this.dest[i].title = '活动商品,购买满' + derate[0].order_full + '元; ' + '享受' + derate[0].discount * 10 + '折优惠';
                            //满额打折非等步长的
                            var maxDiscount; //取出满足的折扣
                            for (var j = 0; j < derate.length; j++) {
                                if (this.dest[i].marketPrice >= derate[j].order_full) {
                                    maxDiscount = derate[j];
                                }
                            }
                            if (maxDiscount) {
                                this.dest[i].onOff = true;
                                this.dest[i].total_price = keepTwoDecimalFull(this.dest[i].marketPrice);
                                this.dest[i].title = '活动商品,已满' + maxDiscount.order_full + '元; ' + '已享受' + maxDiscount.discount * 10 + '折优惠';
                                this.dest[i].subtotal = keepTwoDecimalFull(parseFloat(this.dest[i].marketPrice * maxDiscount.discount));
                                this.dest[i].reducePrice = keepTwoDecimalFull(parseFloat(this.dest[i].marketPrice - this.dest[i].subtotal));
                            } else {
                                this.dest[i].reducePrice = 0;
                                this.dest[i].total_price = keepTwoDecimalFull(this.dest[i].marketPrice);
                                this.dest[i].onOff = false;
                                this.dest[i].subtotal = keepTwoDecimalFull(parseFloat(this.dest[i].marketPrice));
                            }
                        } else if (discount == 3 && full_type == 1 && step_flag == false) {
                            this.dest[i].title = '活动商品,购买满' + derate[0].order_full + '元; ' + '享受' + derate[0].discount + '件商品减免';
                            //满额免件，免便宜的商品 ，非等步长
                            var avoid_number; //取出满足的折扣
                            var goods_price = [];
                            var freeMoney = 0;
                            for (var h = 0; h < this.dest[i].data.length; h++) {
                                if (this.dest[i].data[h].Cart.selected_flag) {
                                    goods_price.push(this.dest[i].data[h].Goods.goods_price);
                                }
                            }

                            for (var k = 0; k < derate.length; k++) {
                                if (this.dest[i].marketPrice > derate[k].order_full) {
                                    avoid_number = derate[k];
                                }
                            }
                            var len = goods_price.length;
                            for (var l = 0; l < len; l++) {
                                for (var j = 0; j < len - 1 - l; j++) {
                                    if (goods_price[j] > goods_price[j + 1]) {
                                        // 相邻元素两两对比
                                        var temp = goods_price[j + 1]; // 元素交换
                                        goods_price[j + 1] = goods_price[j];
                                        goods_price[j] = temp;
                                    }
                                }
                            }
                            if (avoid_number) {
                                var index = avoid_number.discount;
                                var goods_prices = goods_price.slice(0, index);

                                for (var m = 0; m < goods_prices.length; m++) {
                                    freeMoney += goods_prices[m];
                                }
                                this.dest[i].onOff = true;
                                this.dest[i].total_price = keepTwoDecimalFull(this.dest[i].marketPrice);
                                this.dest[i].title = "活动商品,已满" + avoid_number.order_full + '元; ' + '已享受' + avoid_number.discount + '件优惠';
                                this.dest[i].reducePrice = keepTwoDecimalFull(parseFloat(freeMoney));
                                this.dest[i].subtotal = keepTwoDecimalFull(parseFloat(this.dest[i].marketPrice - freeMoney));
                            } else {
                                this.dest[i].onOff = false;
                                this.dest[i].total_price = keepTwoDecimalFull(this.dest[i].marketPrice);
                                this.dest[i].reducePrice = 0;
                                this.dest[i].subtotal = keepTwoDecimalFull(parseFloat(this.dest[i].marketPrice));
                            }
                        } else if (discount == 1 && full_type == 2 && step_flag == false) {
                            this.dest[i].title = '活动商品,购买满' + derate[0].order_full + '件商品; ' + '即减' + derate[0].discount + '元';
                            //满件减钱非等步长
                            var maxDiscount;
                            for (var k = 0; k < derate.length; k++) {
                                if (this.dest[i].fullPrice >= derate[k].order_full) {
                                    var maxDiscount = derate[k];
                                }
                            }
                            if (maxDiscount) {
                                this.dest[i].onOff = true;
                                this.dest[i].total_price = keepTwoDecimalFull(this.dest[i].marketPrice);
                                this.dest[i].title = "活动商品,已满" + maxDiscount.order_full + '件商品; ' + '即减' + maxDiscount.discount + '元';
                                this.dest[i].reducePrice = keepTwoDecimalFull(parseFloat(maxDiscount.discount));
                                this.dest[i].subtotal = keepTwoDecimalFull(parseFloat(this.dest[i].marketPrice - this.dest[i].reducePrice));
                            } else {
                                this.dest[i].onOff = false;
                                this.dest[i].total_price = keepTwoDecimalFull(this.dest[i].marketPrice);
                                this.dest[i].reducePrice = 0;
                                this.dest[i].subtotal = keepTwoDecimalFull(parseFloat(this.dest[i].marketPrice));
                            }
                        } else if (discount == 2 && full_type == 2 && step_flag == false) {
                            this.dest[i].title = '活动商品,购买满' + derate[0].order_full + '件商品; ' + '即享受' + derate[0].discount * 10 + '折优惠';
                            //满件打折非等步长
                            var maxDiscount;
                            for (var k = 0; k < derate.length; k++) {
                                if (this.dest[i].fullPrice >= derate[k].order_full) {
                                    maxDiscount = derate[k];
                                };
                            }
                            if (maxDiscount) {
                                this.dest[i].onOff = true;
                                this.dest[i].total_price = keepTwoDecimalFull(this.dest[i].marketPrice);
                                this.dest[i].title = "活动商品,已满" + maxDiscount.order_full + '件商品; ' + '已享受' + maxDiscount.discount * 10 + '折优惠';
                                this.dest[i].subtotal = keepTwoDecimalFull(parseFloat(this.dest[i].marketPrice * maxDiscount.discount));
                                this.dest[i].reducePrice = keepTwoDecimalFull(parseFloat(this.dest[i].marketPrice - this.dest[i].subtotal));
                            } else {
                                this.dest[i].onOff = false;
                                this.dest[i].total_price = keepTwoDecimalFull(this.dest[i].marketPrice);
                                this.dest[i].reducePrice = 0;
                                this.dest[i].subtotal = keepTwoDecimalFull(parseFloat(this.dest[i].marketPrice));
                            }
                        } else if (discount == 3 && full_type == 2 && step_flag == false) {
                            //满件免件非等步长
                            this.dest[i].title = '活动商品,购买满' + derate[0].order_full + '件商品; ' + '即享受' + derate[0].discount + '件商品减免';
                            var avoid_number; //取出满足的折扣
                            var goods_price = [];
                            var freeMoney = 0;
                            for (var h = 0; h < this.dest[i].data.length; h++) {
                                if (this.dest[i].data[h].Cart.selected_flag) {
                                    goods_price.push(this.dest[i].data[h].Goods.promotion_price);
                                }
                            }

                            for (var k = 0; k < derate.length; k++) {
                                if (this.dest[i].fullPrice >= derate[k].order_full) {
                                    avoid_number = derate[k];
                                }
                            }
                            var len = goods_price.length;
                            for (var l = 0; l < len; l++) {
                                for (var j = 0; j < len - 1 - l; j++) {
                                    if (goods_price[j] > goods_price[j + 1]) {
                                        // 相邻元素两两对比
                                        var temp = goods_price[j + 1]; // 元素交换
                                        goods_price[j + 1] = goods_price[j];
                                        goods_price[j] = temp;
                                    }
                                }
                            }

                            if (avoid_number) {
                                var index = avoid_number.discount;
                                var goods_prices = goods_price.slice(0, index);
                                this.dest[i].onOff = true;
                                for (var m = 0; m < goods_prices.length; m++) {
                                    freeMoney += goods_prices[m];
                                }
                                this.dest[i].total_price = keepTwoDecimalFull(this.dest[i].marketPrice);
                                this.dest[i].title = "活动商品,已满" + avoid_number.order_full + '件商品; ' + '已享受' + avoid_number.discount + '件商品减免';
                                this.dest[i].reducePrice = keepTwoDecimalFull(parseFloat(freeMoney));
                                this.dest[i].subtotal = keepTwoDecimalFull(parseFloat(this.dest[i].marketPrice - freeMoney));
                            } else {
                                this.dest[i].onOff = false;
                                this.dest[i].total_price = keepTwoDecimalFull(this.dest[i].marketPrice);
                                this.dest[i].reducePrice = 0;
                                this.dest[i].subtotal = keepTwoDecimalFull(parseFloat(this.dest[i].marketPrice));
                            }
                        }
                    } else if (this.dest[i].data[0].ActivityDerate && this.dest[i].data[0].ActivityGift && this.dest[i].data[0].Goods.promotion_flag != 1) {

                        //送赠品

                        // var gift_count = this.dest[i].data[0].ActivityGift.gift_count;
                        // var add_gift_count = this.dest[i].data[0].ActivityGift.add_gift_count;
                        // var ActivityGift =  this.dest[i].data[0].ActivityGift;
                        //满额送赠品/加价购

                        if (this.dest[i].data[0].ActivityGift.full_type == 1) {
                            var ActivityGift = this.dest[i].data[0].ActivityGift;
                            if (this.dest[i].marketPrice < ActivityGift.order_full) {
                                arr_goods_id = [];
                                this.dest[i].data.forEach(function (el) {

                                    if (el.Goods.gift_flag) {
                                        arr_goods_id.push(el.Goods.id);
                                        _this.deleteAll();
                                    }
                                });

                                this.dest[i].onOff = false;
                                this.dest[i].total_price = keepTwoDecimalFull(this.dest[i].marketPrice);
                                this.dest[i].reducePrice = 0;
                                this.dest[i].subtotal = keepTwoDecimalFull(parseFloat(this.dest[i].marketPrice));
                                this.dest[i].title = '活动商品,购买满' + ActivityGift.order_full + '元;' + '即享受' + ActivityGift.gift_count + '件赠品';
                            } else if (this.dest[i].marketPrice >= ActivityGift.order_full) {
                                this.dest[i].onOff = true;
                                this.dest[i].total_price = keepTwoDecimalFull(this.dest[i].marketPrice);
                                this.dest[i].reducePrice = 0;
                                this.dest[i].subtotal = keepTwoDecimalFull(parseFloat(this.dest[i].marketPrice));
                                this.dest[i].title = '活动商品,已满' + ActivityGift.order_full + '元;' + '即享受' + ActivityGift.gift_count + '件赠品';
                            }
                        } else if (this.dest[i].data[0].ActivityGift.full_type == 2) {

                            //满件送赠品/选择加价购商品
                            var ActivityGift = this.dest[i].data[0].ActivityGift;
                            if (this.dest[i].fullPrice < ActivityGift.order_full) {
                                arr_goods_id = [];
                                this.dest[i].data.forEach(function (el) {
                                    if (el.Goods.gift_flag) {
                                        arr_goods_id.push(el.Goods.id);
                                        _this.deleteAll();
                                    }
                                });
                                this.dest[i].onOff = false;
                                this.dest[i].total_price = keepTwoDecimalFull(this.dest[i].marketPrice);
                                this.dest[i].reducePrice = 0;
                                this.dest[i].subtotal = keepTwoDecimalFull(parseFloat(this.dest[i].marketPrice));
                                this.dest[i].title = '活动商品,购买满' + ActivityGift.order_full + '件;' + '即享受' + ActivityGift.gift_count + '件赠品;' + '加价购可选' + ActivityGift.add_gift_count + '件商品';
                            } else if (this.dest[i].fullPrice >= ActivityGift.order_full) {

                                this.dest[i].onOff = true;
                                this.dest[i].total_price = keepTwoDecimalFull(this.dest[i].marketPrice);
                                this.dest[i].reducePrice = 0;
                                this.dest[i].subtotal = keepTwoDecimalFull(parseFloat(this.dest[i].marketPrice));
                                this.dest[i].title = '活动商品,已满' + ActivityGift.order_full + '件;' + '享受' + ActivityGift.gift_count + '件赠品;' + '加价购可选' + ActivityGift.add_gift_count + '件商品';
                            }
                        }
                    } else if (this.dest[i].data[0].ActivityVirtualCoupon && this.dest[i].data[0].Goods.promotion_flag != 1) {
                        //送优惠券
                        var full_type = this.dest[i].data[0].ActivityVirtual.full_type;
                        var virtual_type = this.dest[i].data[0].ActivityVirtual.virtual_type;
                        var ActivityVirtualCoupon = this.dest[i].data[0].ActivityVirtualCoupon;
                        //满额送优惠券
                        if (full_type == 1 && virtual_type == 2) {
                            if (this.dest[i].marketPrice < ActivityVirtualCoupon.order_full) {
                                //优惠券查询/删除
                                var couponParams = {
                                    'CartCoupon': {
                                        'user_id': id,
                                        'activity_id': this.dest[i].data[0].Activity.id
                                    }
                                };
                                send_ajax('post', '/get', couponParams, function callback(data) {
                                    if (data.code == 200 && data.CartCoupon) {
                                        var delete_coupon = {
                                            'CartCoupon': {
                                                'user_id': id,
                                                'coupon_id': _this.dest[i].data[0].Coupon.id,
                                                'activity_id': _this.dest[i].data[0].Activity.id
                                            },
                                            'Tag': 'CartCoupon'
                                        };
                                        send_ajax('post', '/delete', delete_coupon, function callback(result) {
                                            if (result.code == 200) {}
                                        });
                                    }
                                });

                                this.dest[i].onOff = false;
                                this.dest[i].total_price = keepTwoDecimalFull(this.dest[i].marketPrice);
                                this.dest[i].title = '活动商品,购买满' + ActivityVirtualCoupon.order_full + '元;' + '即享受送优惠劵活动';
                                this.dest[i].reducePrice = keepTwoDecimalFull(0);
                                this.dest[i].subtotal = keepTwoDecimalFull(parseFloat(this.dest[i].marketPrice));
                            } else {
                                this.dest[i].onOff = true;
                                this.dest[i].total_price = keepTwoDecimalFull(this.dest[i].marketPrice);
                                this.coupon = this.dest[i].data[0].Coupon.name;
                                this.dest[i].title = '活动商品,已满' + ActivityVirtualCoupon.order_full + '元;' + '领取优惠劵';
                                this.dest[i].reducePrice = keepTwoDecimalFull(0);
                                this.dest[i].subtotal = keepTwoDecimalFull(parseFloat(this.dest[i].marketPrice));
                            }
                            //满件送优惠劵
                        } else if (full_type == 2 && virtual_type == 2) {
                            if (this.dest[i].fullPrice < ActivityVirtualCoupon.order_full) {
                                //优惠券查询/删除
                                var couponParams = {
                                    'CartCoupon': {
                                        'user_id': id,
                                        'activity_id': this.dest[i].data[0].Activity.id
                                    }
                                };
                                send_ajax('post', '/get', couponParams, function callback(data) {
                                    if (data.code == 200 && data.CartCoupon) {
                                        var delete_param = {
                                            'CartCoupon': {
                                                'user_id': id,
                                                'coupon_id': _this.dest[i].data[0].Coupon.id,
                                                'activity_id': _this.dest[i].data[0].Activity.id
                                            },
                                            'Tag': 'CartCoupon'
                                        };
                                        send_ajax('post', '/delete', delete_param, function callback(result) {
                                            if (result.code == 200) {}
                                        });
                                    }
                                });
                                this.dest[i].onOff = false;
                                this.dest[i].total_price = keepTwoDecimalFull(this.dest[i].marketPrice);
                                this.dest[i].title = '活动商品,购买满' + ActivityVirtualCoupon.order_full + '件;' + '即享受送优惠劵活动';
                                this.dest[i].reducePrice = keepTwoDecimalFull(0);
                                this.dest[i].subtotal = keepTwoDecimalFull(parseFloat(this.dest[i].marketPrice));
                            } else {
                                this.dest[i].onOff = true;
                                this.dest[i].total_price = keepTwoDecimalFull(this.dest[i].marketPrice);
                                this.coupon = this.dest[i].data[0].Coupon.name;
                                this.dest[i].title = '活动商品,已满' + ActivityVirtualCoupon.order_full + '件;' + '领取优惠劵';
                                this.dest[i].reducePrice = keepTwoDecimalFull(0);
                                this.dest[i].subtotal = keepTwoDecimalFull(parseFloat(this.dest[i].marketPrice));
                            }
                        }
                    } else {
                        if (this.dest[i].data[0].Goods.promotion_flag == 1) {
                            this.dest[i].title = '特价商品';
                            this.dest[i].onOff = true;
                            this.dest[i].total_price = keepTwoDecimalFull(this.dest[i].marketPrice);
                            this.dest[i].subtotal = keepTwoDecimalFull(parseFloat(this.dest[i].bargains));
                            this.dest[i].reducePrice = keepTwoDecimalFull(parseFloat(this.dest[i].marketPrice - this.dest[i].bargains));
                        } else {
                            this.dest[i].onOff = true;
                            this.dest[i].total_price = keepTwoDecimalFull(this.dest[i].marketPrice);
                            this.dest[i].title = '不参加活动商品';
                            this.dest[i].reducePrice = keepTwoDecimalFull(0);
                            this.dest[i].subtotal = keepTwoDecimalFull(parseFloat(this.dest[i].marketPrice));
                        }
                    }
                }
            },
            //切换选择活动
            selectActivity: function selectActivity(activity_id, cart_id) {
                this.activity_rule_id = activity_id;

                this.cart_id = cart_id;

                this.activity_rule_id = activity_id;
            },

            //切换活动确定
            sure: function sure(item, index, option) {
                var _this = this;
                var arr = [];
                arr.push(item.Goods.id);
                var selectParam = {
                    user_id: id,
                    goods_ids: arr,
                    select_flag: 0
                };
                var param;
                if (this.activity_rule_id == null) {
                    param = {
                        "Cart": {
                            "id": this.cart_id,
                            "activity_selected": 0,
                            "activity_id": null
                        },
                        "tag": "Cart"
                    };
                } else {
                    param = {
                        "Cart": {
                            "id": this.cart_id,
                            "activity_id": this.activity_rule_id,
                            "activity_selected": 1
                        },
                        "tag": "Cart"
                    };
                }
                if (this.cart_id >= 0) {
                    //切换活动请求
                    send_ajax('post', '/put', param, function callback(data) {
                        if (data.code == 200) {
                            send_ajax('post', '/api/cart/select', selectParam, function callback(data) {
                                if (data.code == 200) {
                                    _this.again_data();
                                }
                            });
                            _this.currentGoodsIndex = -1;
                            _this.currentActivityIndex = -1;
                            _this.rules = [];
                        }
                    });
                } else {
                    _this.currentGoodsIndex = -1;
                    _this.currentActivityIndex = -1;
                    _this.rules = [];
                }
            },
            //取消
            close: function close() {
                this.currentGoodsIndex = -1;
                this.currentActivityIndex = -1;
                this.rules = [];
            },

            //单个删除
            deletes: function deletes(option, item) {
                var _this = this;
                var arr = [];
                arr.push(item.Goods.id);
                var param = {
                    user_id: id,
                    goods_ids: arr,
                    type: 0
                };
                var ActivityGiftGoods = option.data.filter(function (el) {
                    return el.ActivityGiftGoods;
                });
                if (ActivityGiftGoods.length !== 0) {
                    if (item.ActivityGift.full_type == 2 && option.fullPrice - 1 < item.ActivityGift.order_full && !item.Goods.gift_flag) {

                        swal({
                            // title: 'Are you sure?',
                            text: "删除此商品后将不满足赠品/加价购/购买条件，是否删除!",
                            type: 'warning',
                            showCancelButton: true,
                            confirmButtonColor: '#3AD997',
                            cancelButtonColor: '#EEE',
                            confirmButtonText: '确定',
                            cancelButtonText: '取消'
                        }).then(function (isConfirm) {
                            if (isConfirm) {
                                var gifeGoodsAll = _this.giveGiftChoose.concat(_this.markUplIistChoose);
                                var arr = [];
                                arr.push(item.Goods.id);
                                arr.push(item.Goods.id);
                                var goodsAll = arr.concat(gifeGoodsAll);
                                var param_gift = {
                                    user_id: id,
                                    goods_ids: goodsAll,
                                    type: 0
                                };
                                //删除商品
                                send_ajax('post', '/api/cart/add', param_gift, function callback(data) {
                                    if (data.code == 200) {
                                        for (var i = 0; i < goodsAll.length; i++) {
                                            _this.deletesGoods(option, goodsAll[i]);
                                        };
                                    }
                                });
                            }
                        });
                    } else if (item.ActivityGift.full_type == 1 && option.marketPrice - item.Goods.promotion_price < item.ActivityGift.order_full && !item.Goods.gift_flag) {
                        swal({
                            // title: 'Are you sure?',
                            text: "删除此商品后将不满足赠品/加价购/购买条件，是否删除!",
                            type: 'warning',
                            showCancelButton: true,
                            confirmButtonColor: '#3AD997',
                            cancelButtonColor: '#EEE',
                            confirmButtonText: '确定',
                            cancelButtonText: '取消'
                        }).then(function (isConfirm) {
                            if (isConfirm) {
                                var gifeGoodsAll = _this.giveGiftChoose.concat(_this.markUplIistChoose);
                                var arr = [];
                                arr.push(item.Goods.id);
                                var goodsAll = arr.concat(gifeGoodsAll);
                                var param_gift = {
                                    user_id: id,
                                    goods_ids: goodsAll,
                                    type: 0
                                };
                                send_ajax('post', '/api/cart/add', param_gift, function callback(data) {
                                    if (data.code == 200) {
                                        for (var i = 0; i < goodsAll.length; i++) {
                                            _this.deletesGoods(option, goodsAll[i]);
                                        };
                                    };
                                });
                            }
                        });
                    } else {
                        send_ajax('post', '/api/cart/add', param, function callback(data) {
                            if (data.code == 200) {
                                _this.deletesGoods(option, item.Goods.id);
                            }
                        });
                    }
                } else if (item.Coupon) {
                    var param_d = {
                        'CartCoupon': {
                            'user_id': id,
                            'coupon_id': item.Coupon.id,
                            'activity_id': item.Activity.id
                        },
                        'Tag': 'CartCoupon'
                    };
                    var couponParams = {
                        'CartCoupon': {
                            'user_id': id,
                            'activity_id': item.Activity.id
                        }
                    };
                    send_ajax('post', '/get', couponParams, function callback(data) {
                        if (data.code == 200 && data.CartCoupon) {
                            //优惠券记录删除
                            if (item.Coupon && item.ActivityVirtual.full_type == 2 && option.fullPrice - 1 < item.ActivityVirtualCoupon.order_full) {
                                swal({
                                    text: "删除此商品后将不满足优惠券领取，是否取消!",
                                    type: 'warning',
                                    showCancelButton: true,
                                    confirmButtonColor: '#3AD997',
                                    cancelButtonColor: '#EEE',
                                    confirmButtonText: '确定',
                                    cancelButtonText: '取消'
                                }).then(function (isConfirm) {
                                    if (isConfirm) {
                                        send_ajax('post', '/delete', param_d, function callback(data) {
                                            if (data.code == 200) {
                                                var arr = [];
                                                arr.push(item.Goods.id);
                                                var param = {
                                                    user_id: id,
                                                    goods_ids: arr,
                                                    type: 0
                                                };
                                                send_ajax('post', '/api/cart/add', param, function callback(data) {
                                                    if (data.code == 200) {
                                                        _this.again_data();
                                                    }
                                                });
                                            }
                                        });
                                    } else {
                                        var arr = [];
                                        arr.push(item.Goods.id);
                                        var params = {
                                            user_id: id,
                                            goods_ids: arr,
                                            select_flag: 1
                                        };
                                        send_ajax('post', '/api/cart/select', params, function callback(data) {
                                            if (data.code == 200) {
                                                _this.again_data();
                                            }
                                        });
                                    }
                                });

                                send_ajax('post', '/delete', param_d, function callback(data) {});
                            } else if (item.Coupon && item.ActivityVirtual.full_type == 1 && option.marketPrice - item.Goods.promotion_price < item.ActivityVirtualCoupon.order_full) {
                                swal({
                                    text: "删除此商品后将不满足优惠券领取，是否取消!",
                                    type: 'warning',
                                    showCancelButton: true,
                                    confirmButtonColor: '#3AD997',
                                    cancelButtonColor: '#EEE',
                                    confirmButtonText: '确定',
                                    cancelButtonText: '取消'
                                }).then(function (isConfirm) {
                                    if (isConfirm) {
                                        //  var delete_param={
                                        //     'CartCoupon': {
                                        //         'user_id':id,
                                        //         'coupon_id':item.Coupon.id,
                                        //         'activity_id': item.Activity.id
                                        //     },
                                        //     'Tag': 'CartCoupon'
                                        //     }

                                        send_ajax('post', '/delete', param_d, function callback(data) {
                                            if (data.code == 200) {
                                                var arr = [];
                                                arr.push(item.Goods.id);
                                                var param = {
                                                    user_id: id,
                                                    goods_ids: arr,
                                                    type: 5
                                                };
                                                send_ajax('post', '/api/cart/add', param, function callback(data) {
                                                    if (data.code == 200) {

                                                        _this.again_data();
                                                    }
                                                });
                                            }
                                        });
                                    } else {
                                        var arr = [];
                                        arr.push(item.Goods.id);
                                        var param = {
                                            user_id: id,
                                            goods_ids: arr,
                                            select_flag: 1
                                        };
                                        send_ajax('post', '/api/cart/select', param, function callback(data) {
                                            if (data.code == 200) {
                                                _this.again_data();
                                            }
                                        });
                                    }
                                });
                            }
                        } else {
                            send_ajax('post', '/api/cart/add', param, function callback(data) {
                                if (data.code == 200) {

                                    _this.again_data();
                                }
                            });
                        }
                    });
                } else {
                    send_ajax('post', '/api/cart/add', param, function callback(data) {
                        if (data.code == 200) {
                            _this.deletesGoods(option, item.Goods.id);
                        };
                    });
                }
            },
            deletesGoods: function deletesGoods(option, goodsId) {
                option.data = option.data.filter(function (el) {
                    return el.Goods.id != goodsId;
                });
                if (option.data.length == 0) {
                    this.dest = this.dest.filter(function (el) {
                        return el.id != option.id;
                    });
                };
                for (var k = 0; k < this.dest.length; k++) {
                    this.dest[k].bargains = 0;
                    this.dest[k].fullPrice = 0;
                    this.dest[k].marketPrice = 0;
                    this.dest[k].reducePrice = 0;
                    this.dest[k].subtotal = 0;
                    for (var n = 0; n < this.dest[k].data.length; n++) {
                        goods_id_All.push(this.dest[k].data[n].Goods.id);
                        if (this.dest[k].data[n].Cart.selected_flag == true) {
                            this.isSelected(this.dest[k].data[n], this.dest[k]);
                        }
                    }
                };
                this.getTotalPrice();
                this.count_price();
            },
            //收藏
            storeUp: function storeUp(goods_id) {
                var param = {
                    "GoodsCollect": {
                        "goods_id": goods_id,
                        "user_id": id
                    },
                    "tag": "GoodsCollect"
                };
                send_ajax('post', '/post', param, function callback(data) {
                    if (data.code == 200) {
                        alert('收藏成功');
                    }
                });
            },

            //多选选删除
            deleteAll: function deleteAll() {
                var _this = this;
                var param = {
                    user_id: id,
                    goods_ids: arr_goods_id,
                    type: 0
                };
                send_ajax('post', '/api/cart/add', param, function callback(data) {
                    if (data.code == 200) {
                        _this.again_data();
                    }
                });
            },

            //赠品
            activityGift: function activityGift(activity_gift_id, item) {
                var _this = this;
                this.giveGiftChoose = [];
                item.data.forEach(function (el) {
                    if (el.ActivityGiftGoods && el.ActivityGiftGoods.add_price == 0) {
                        _this.giveGiftChoose.push(el.Goods.id);
                    }
                    return _this.giveGiftChoose;
                });
                var activity_gift_id = activity_gift_id.ActivityGift.id;
                this.giftId = item.id;
                this.giveGiftOff = !this.giveGiftOff;
                this.purchasedOff = false;
                var _this = this;
                var param = {
                    '[]': {
                        'ActivityGiftGoods': {
                            'activity_gift_id': activity_gift_id,
                            'add_price': '0'
                        },
                        'Goods': {
                            'id@': '/ActivityGiftGoods/goods_id'
                        },
                        'GoodsImgs': {
                            'goods_id@': '/ActivityGiftGoods/goods_id'
                        }
                    }
                };
                if (this.giveGiftOff) {
                    send_ajax('post', '/get', param, function callback(result) {
                        if (result.code == 200) {
                            _this.giveGift = result["[]"];
                        }
                    });
                }
            },

            //加价购
            markUp: function markUp(activity_gift_id, item) {
                var _this = this;
                this.markUplIistChoose = [];

                item.data.forEach(function (el) {

                    if (el.ActivityGiftGoods && el.ActivityGiftGoods.add_price > 0) {

                        _this.markUplIistChoose.push(el.Goods.id);
                    }
                    return _this.markUplIistChoose;
                });

                this.purchasedOff = !this.purchasedOff;
                this.giveGiftOff = false;
                var activity_gift_id = activity_gift_id.ActivityGift.id;

                var param = {
                    '[]': {
                        'ActivityGiftGoods': {
                            'activity_gift_id': activity_gift_id,
                            'add_price!': '0'
                        },
                        'Goods': {
                            'id@': '/ActivityGiftGoods/goods_id'
                        },
                        'GoodsImgs': {
                            'goods_id@': '/ActivityGiftGoods/goods_id'
                        }
                    }
                };
                send_ajax('post', '/get', param, function callback(result) {
                    if (result.code == 200) {
                        _this.markUplIist = result["[]"];
                    }
                });
            },
            //跳转商品详情页
            jumpGoodsDetail: function jumpGoodsDetail(goodsId) {
                window.location.href = "/goods-" + goodsId + '.html'
            },

            //赠品选择
            selectedInput: function selectedInput(limitGiftNumber, goods_id) {

                if (this.giveGiftChoose.indexOf(goods_id) == -1) {
                    if (this.giveGiftChoose.length < limitGiftNumber) {
                        this.giveGiftChoose.push(goods_id);
                    } else {
                        alert('只能选择' + limitGiftNumber);
                    }
                } else {
                    this.giveGiftChoose = this.giveGiftChoose.filter(function (el) {
                        return el != goods_id;
                    });
                }
            },

            //加价购选择的商品
            markUpSelectedInput: function markUpSelectedInput(limitMarkUpNumber, goods_id) {
                if (this.markUplIistChoose.indexOf(goods_id) == -1) {
                    if (this.markUplIistChoose.length < limitMarkUpNumber) {
                        this.markUplIistChoose.push(goods_id);
                    } else {
                        alert('只能选择' + limitMarkUpNumber);
                    }
                } else {
                    this.markUplIistChoose = this.markUplIistChoose.filter(function (el) {
                        return el != goods_id;
                    });
                }
            },

            //取消
            cancel: function cancel() {
                this.giveGiftOff = false;
                this.purchasedOff = false;
            },

            //赠品/加价购选择提交按钮
            submit: function submit(gift, activity_id) {
                //gift==1是提交的赠品
                //gift==2是提交的加价购

                var _this = this;
                var user = JSON.parse(localStorage.getItem('user_info')) || {};
                var id = user.id;
                var param;
                if (gift == 1) {
                    param = {
                        'user_id': id,
                        'goods_ids': this.giveGiftChoose,
                        'activity_id': activity_id,
                        type: 1
                    };
                } else {
                    param = {
                        'user_id': id,
                        'goods_ids': this.markUplIistChoose,
                        'activity_id': activity_id,
                        type: 1
                    };
                }
                send_ajax('post', '/api/cart/add', param, function callback(result) {
                    if (result.code == 200) {
                        _this.giveGiftOff = false;
                        _this.purchasedOff = false;
                        _this.again_data();
                    }
                });
            },

            //购物车去结算
            submit_order: function submit_order() {
                if (this.totalPrice != '0.00') {
                    window.location.href = "/goods/submin_order.html";
                } else {
                    alert('请选择您要购买的商品！');
                }
            },
            //获取总价钱
            getTotalPrice: function getTotalPrice() {
                var _this = this;
                var param = {
                    "user_id": id,
                    "point": 0
                };
                send_ajax('post', '/api/cart/amt', param, function callback(result) {
                    if (result.code == 200) {
                        var data = result.data;
                        _this.totalPrice = keepTwoDecimalFull(data.totalSum - data.discountAmt-data.discountPointAmt);
                    }
                });
            },
            noUsersingleChecked: function noUsersingleChecked(goodsId) {
                //没有登录的单选
                this.noUserGoodsList.filter(function (el) {
                    if (el.id == goodsId) {
                        return el.selected_flag = !el.selected_flag;
                    }
                });
                localStorage.setItem("noUsers", JSON.stringify(this.noUserGoodsList));
                this.noUserPrice();
            },
            noUserPrice: function noUserPrice() {
                //没有登录的计算价格
                var goodsList = JSON.parse(localStorage.getItem('noUsers')) || [];
                this.noLoginPrice = 0;
                this.number = 0;
                this.storeNoLoginGoodsId = [];
                for (var i = 0; i < goodsList.length; i++) {
                    if (goodsList[i].selected_flag) {
                        if (goodsList[i].promotion_flag == 1) {
                            this.noLoginPrice += goodsList[i].promotion_price;
                        } else if (goodsList[i].promotion_flag != 1) {
                            this.noLoginPrice += goodsList[i].goods_price;
                        }
                        this.storeNoLoginGoodsId.push(goodsList[i].id);
                        this.number++;
                    }
                };
                this.noLoginPriceString = keepTwoDecimalFull(this.noLoginPrice);
            },
            noUsercheckAll: function noUsercheckAll() {
                //没有登录的全选
                this.isCheckedAll = !this.isCheckedAll;
                var data = this.noUserGoodsList;
                this.storeNoLoginGoodsId = [];
                this.noLoginPrice = 0;
                this.number = 0;
                for (var i = 0; i < data.length; i++) {
                    data[i].selected_flag = this.isCheckedAll;
                    if (data[i].selected_flag) {
                        if (data[i].promotion_flag == 1) {
                            this.noLoginPrice += data[i].promotion_price;
                        } else if (data[i].promotion_flag != 1) {
                            this.noLoginPrice += data[i].goods_price;
                        }
                        this.storeNoLoginGoodsId.push(data[i].id);
                        this.number++;
                    }
                };
                this.noLoginPriceString = keepTwoDecimalFull(this.noLoginPrice);
                localStorage.setItem("noUsers", JSON.stringify(data));
            },
            noUserdeletes: function noUserdeletes(goodsId) {
                //没有登录的删除
                this.noUserGoodsList = this.noUserGoodsList.filter(function (el) {
                    return el.id != goodsId;
                });
                localStorage.setItem("noUsers", JSON.stringify(this.noUserGoodsList));
                this.noUserPrice();
            },
            noUserdeleteAll: function noUserdeleteAll() {
                //没有登录的多选删除
                var data = this.storeNoLoginGoodsId;
                var noUserGoodsList = this.noUserGoodsList;
                if (data.length) {
                    for (var i = 0; i < data.length; i++) {
                        for (var k = 0; k < noUserGoodsList.length; k++) {
                            if (data[i] == noUserGoodsList[k].id) {
                                noUserGoodsList.splice(k, 1);
                            }
                        }
                    };
                    localStorage.setItem("noUsers", JSON.stringify(noUserGoodsList));
                }
            },
            noUserSubmit_order: function noUserSubmit_order() {
                //无用户提交订单
                if (this.number != '0') {
                    window.location.href = "/goods/submin_order.html";
                } else {
                    alert('请选择您要购买的商品！');
                }
            }
        },
        created: function created() {
            this.again_data();
        }

    });
    // 数字数组由大到小排序 
    function util() {
        this.max2min = function (v) {
            if (v.constructor == Array) {
                var oValue;
                for (var i = 0, len = v.length; i < len; i++) {
                    for (var j = 0; j <= i; j++) {
                        if (v[i].id > v[j].id) {
                            oValue = v[i];
                            v[i] = v[j];
                            v[j] = oValue;
                        }
                    }
                }
                return v;
            }
        };
    };
});